new Vue({
	el: "#app", 
	data: {
		province_arr: [],
		current_province: "西安市",
		selected_province: 61,
		imgUrl: "https://app.meijiangzi.com/static/"
	}, 
	methods: {
		get_data: function() {
			var t = this;
			wx.showLoading({
				title: "加载中...",
				mask: !0,
				success: function(t) {}
			}), this.$http.post(baseUrl+"dict/getList", {
			  dictType: 'zone',
			  pid: 0
			}).then(function(e) {
				wx.hideLoading();
				var n = e.data;
				n.success ? (n.data.forEach(function(e) {
					console.log(t.selected_province);
					t.selected_province - 0 == e.id ? e.active = 1 : 0;
				}), t.province_arr = n.data) : wx.showToast({
					title: n.description,
					icon: "none",
					duration: 2e3,
					mask: !1
				});
			}).catch(function(t) {
				console.log(t), wx.hideLoading(), wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !1
				});
			});
		},
		select_province: function(t) {
			var e = [].concat(this.province_arr);
			e.forEach(function(e) {
				e.id == t.id ? e.active = !0 : e.active = !1;
			}), this.province_arr = e, wx.setStorageSync("province_info", JSON.stringify({
				province_name: t.name,
				province_id: t.id
			})), Jump.back();
		},
		sellect_current: function() {
			var t = this;
			this.province_arr.forEach(function(e) {
				e.name == t.current_province && (wx.setStorageSync("province_info", JSON.stringify({
					province_name: e.name,
					province_id: e.id
				}))), Jump.back();
			});
		},
		get_location: function() {
			var t = this;
			if(navigator.geolocation) {
				// 百度地图API功能
				var map = new BMap.Map("mapContainer");
				var point = new BMap.Point(t.longitude,t.latitude);
				map.centerAndZoom(point,12);
		
				var geolocation = new BMap.Geolocation();
				geolocation.getCurrentPosition(function(r){
					if(this.getStatus() == BMAP_STATUS_SUCCESS){
						t.longitude = r.point.lng, t.latitude = r.point.lat, t.loadCity();
						wx.setStorageSync("userLng", t.longitude), wx.setStorageSync("userLat", t.latitude);
					} else {
						wx.showToast({
							title: "无法获取地理位置",
							icon: "none",
							duration: 2e3,
							mask: !0
						}), t.current_province = "西安市";
					}        
				},{enableHighAccuracy: true})
			}else{
				wx.showToast({
					title: "无法获取地理位置",
					icon: "none",
					duration: 2e3,
					mask: !0
				}), t.current_province = "西安市";
			}
		},
		loadCity: function() {
			var t = this;
			try{
				$.ajax({
					url: "https://api.map.baidu.com/geocoder/v2/?ak=itcGzLG0IrFlBPQlTFCxytDB10fwNdag&location=" + t.latitude + "," + t.longitude + "&output=json",
					type: "get", 
					dataType:'jsonp',
					data: {}
				}).done(function(a){
					setTimeout(function() {
						var prov = a.result.addressComponent.province, prov_id = a.result.addressComponent.adcode;
						t.current_province = prov;
					}, 50);
				})
				.fail(function(b) {
					t.current_province = "西安市";
					console.log('地址解析失败');
				});
			} catch (e){
				
			}
		}
    },
	created: function() {
		var t = this;
		var e = this;
		const provInfo = wx.getStorageSync("province_info");
		if(provInfo){
			e.selected_province = JSON.parse(provInfo).province_id;
		}
		t.get_data(),t.get_location();
	}
});